package com.apicloud.nodulecreatenotification;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.uzmap.pkg.EntranceActivity;

import org.json.JSONException;
import org.json.JSONObject;

public class ClickService extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public void onCreate() {
        super.onCreate();
    }
    public ClickService(){
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String id = intent.getStringExtra(CreateNotification.EXTRA_PREFIX+"noticeId");
        String action = intent.getStringExtra(CreateNotification.EXTRA_PREFIX+"action");

        if(CreateNotification.list.containsKey(id)){
            CreateNotification createNotification = CreateNotification.list.get(id);
            Intent dialogIntent = new Intent(getBaseContext(), EntranceActivity.class);
            dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getApplication().startActivity(dialogIntent);

            JSONObject ret = new JSONObject();
            try {
                ret.put("status",true).put("msg","event").put("eventName",action).put("data", createNotification.data);
                createNotification.moduleContext.success(ret,false);
            } catch (JSONException e) {
            }
            if(createNotification.autoCancel){
                createNotification.moduleContext.interrupt();
                CreateNotification.list.remove(id);
                stopSelf(startId);
            }
        }else{
            stopSelf(startId);
        }
        return super.onStartCommand(intent, flags, startId);
    }
    @Override
    public void onDestroy(){
    }
}
